
<%@page import="java.net.URI"%>
<%@page import="ahxu.crawler.UriInput"%>
<%@page import="ahxu.crawler.CrawlServiceProvider"%>
<%@page import="ahxu.crawler.CrawlerSite"%>
<%@page import="java.util.List"%>
<%@page import="ahxu.crawler.ICrawlerSiteDao"%>
<%@page import="org.apache.commons.lang.StringUtils"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@page import="ahxu.search.db.PageResults"%>
<%@page import="ahxu.search.db.FinalResult"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.springframework.web.context.WebApplicationContext" %>
<%@page import="ahxu.search.db.IFinalResultDao"%>
<%
String action=request.getParameter("action");
    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(application);
	ICrawlerSiteDao dao=(ICrawlerSiteDao)ctx.getBean("crawlerSiteDao");
	
	if("index".equals(action)){
		
	}else if("insert".equals(action)){
		String id=request.getParameter("id");
		String name=request.getParameter("name");
		String url=request.getParameter("url");
		String isSameSite=request.getParameter("isSameSite");
		System.out.println(isSameSite);
		isSameSite="true".equals(isSameSite)?"true":"false";
		String deep=request.getParameter("deep");
		String total=request.getParameter("total");
		CrawlerSite site=new CrawlerSite();
		site.setId(id);
		site.setLimitSameSite(Boolean.parseBoolean(isSameSite));
		site.setDeep(Integer.parseInt(deep));
		site.setTotal(Integer.parseInt(total));
		UriInput input=new UriInput();
		input.setAnchorText(name);
		input.setUri(new URI(url));
		site.setInput(input);
		dao.save(site);
		RequestDispatcher   rd   =   getServletContext().getRequestDispatcher("/crawler_sites.jsp");  
		rd.forward(request,response); 
	}else if("delete".equals(action)){
		String id=request.getParameter("id");
		dao.delete(id);
		RequestDispatcher   rd   =   getServletContext().getRequestDispatcher("/crawler_sites.jsp");  
		rd.forward(request,response);  
	}else{
		List<CrawlerSite> results=dao.findResults();
	    request.setAttribute("results",results);
	    RequestDispatcher   rd   =   getServletContext().getRequestDispatcher("/crawler_sites.jsp");  
		rd.forward(request,response);   
	}
    
%>